﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace HRDexCapstoneProject
{
    public partial class Default : System.Web.UI.Page
    {
        DataTable dtbl = new DataTable("dtbl");
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        string SessionID()
        {
           return Session["EmployeeID"].ToString();
        }
        protected void btnSumbit_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection    conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\HRdexDB.mdf;Integrated Security=True;User Instance=True");
                SqlDataAdapter cmd = new SqlDataAdapter("SELECT formEmployees.Password, catUserLevel.catUserLevelName FROM formEmployees INNER JOIN  catUserLevel ON formEmployees.UserLevelID = catUserLevel.UserLevelID WHERE formEmployees.EmployeeID = " + txtUsername.Text, conn);



                cmd.Fill(dtbl);

                Session["EmployeeID"] = txtUsername.Text;

                if (txtPassword.Text == dtbl.Rows[0].ItemArray[0].ToString())
                {

                    if (dtbl.Rows[0].ItemArray[1].ToString() == "Employee")
                    {
                        Server.Transfer("~/Functions/MainMenus/EmpMenu.aspx");
                    }
                    else
                    {
                        Server.Transfer("~/Functions/MainMenus/AdminMenu.aspx");
                        Session["parentFolder"] = hrdoc();
                        Session["hrdoc"] = hrdoc();
                        Session["hrcp"] = "12";
                    }

                }
                else
                {
                    lblerror.Visible = true;
                }
            }
            catch (Exception ex)
            {


            }
        }
        public string hrdoc()
        {
            DataTable tblFolder = new DataTable();
            string userid = txtUsername.Text;
            string sqlslct = "SELECT catDepartment.DepartmentName " +
                "FROM catDepartment INNER JOIN formEmployees ON catDepartment.DeptID = formEmployees.DeptID " +
                "WHERE formEmployees.EmployeesID = " + userid;
            SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\HRdexDB.mdf;Integrated Security=True;User Instance=True");
            SqlDataAdapter cmd = new SqlDataAdapter(sqlslct, conn);
            conn.Open();
            cmd.Fill(tblFolder);
            conn.Close();

            switch (tblFolder.Rows[0][0].ToString())
            {
                case "HR Salaries and Benefits":
                    return "2";
                //break;
                case "HR Recruitment and Training":
                    return "5";
                //break;
                case "HR Records and Info":
                    return "3";
                default:
                    return "1";
                //break;
            }

        }
    }
}